package ar.com.mooral.activities;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.app.Activity;
import android.app.ActivityGroup;
import android.app.AlarmManager;
import android.app.LocalActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import ar.com.mooral.crohn.CrohnAlarmReceiver;
import ar.com.mooral.crohn.application.CrohnContext;

	
	

public class MenuPrincipal extends CrohnMenuActivity {
	

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu_principal);
        
        
        // ESTADO GENERAL
        Button btnEstadoGeneral = (Button) findViewById(R.id.btnEstadoGeneral);
        btnEstadoGeneral.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
		    	
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(EstadoGeneral.class.getPackage().getName(), EstadoGeneral.class.getName()));
				//startActivity(intent);

				//Intent frequentMessages = new Intent(getParent(), EstadoGeneral.class);
				//TabGroupActivity parentActivity = (TabGroupActivity)getParent();
				//parentActivity.startChildActivity("EstadoGeneral", frequentMessages);
		    	
		    	//startChildActivity("EstadoGeneral", new Intent(this, EstadoGeneral.class));
		    		    	
				
				
         		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
         		parentActivity.startChildActivity("EstadoGeneral", intent);
				
		    }
		});		

		// DOLOR ABDOMINAL
        Button btnDolorAbdominal = (Button) findViewById(R.id.btnDolorAbdominal);
		btnDolorAbdominal.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(DolorAbdominal.class.getPackage().getName(), DolorAbdominal.class.getName()));
				//startActivity(intent);
//				startChildActivity("DolorAbdominal", intent);
         		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
         		parentActivity.startChildActivity("DolorAbdominal", intent);
				
		    }
		});		

		// DEPOSICIONES
        Button btnDeposiciones = (Button) findViewById(R.id.btnDeposiciones);
        btnDeposiciones.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(Deposiciones.class.getPackage().getName(), Deposiciones.class.getName()));
				//startActivity(intent);
         		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
         		parentActivity.startChildActivity("Deposiciones", intent);
		    }
		});		

		// ALIMENTACION
        Button btnAlimentacion = (Button) findViewById(R.id.btnAlimentacion);
        btnAlimentacion.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(Alimentacion.class.getPackage().getName(), Alimentacion.class.getName()));
				//startActivity(intent);
         		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
         		parentActivity.startChildActivity("Alimentacion", intent);
		    }
		});		
    
		// MEDICACION PERDIDA
        Button btnMedicacionPerdida = (Button) findViewById(R.id.btnMedicacionPerdida);
        btnMedicacionPerdida.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(MedicacionPerdida.class.getPackage().getName(), MedicacionPerdida.class.getName()));
				//startActivity(intent);
         		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
         		parentActivity.startChildActivity("MedicacionPerdida", intent);
		    }
		});
    
		// SINTOMAS PERSONALIZADOS
        Button btnSintomasPersonalizados = (Button) findViewById(R.id.btnSintomasPersonalizados);
        btnSintomasPersonalizados.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(SintomasPersonalizados.class.getPackage().getName(), SintomasPersonalizados.class.getName()));
				//startActivity(intent);
         		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
         		parentActivity.startChildActivity("SintomasPersonalizados", intent);
		    }
		});		
        
		// CALIDAD DE VIDA
        Button btnCalidadDeVida = (Button) findViewById(R.id.btnCalidadDeVida);
        btnCalidadDeVida.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(CalidadDeVida.class.getPackage().getName(), CalidadDeVida.class.getName()));
				//startActivity(intent);
         		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
         		parentActivity.startChildActivity("CalidadDeVida", intent);
		    }
		});		

        
        
        
		/* MENU
        ImageButton btnMenu = (ImageButton) findViewById(R.id.btnMenu);
        btnMenu.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(MenuPrincipal.class.getPackage().getName(), MenuPrincipal.class.getName()));
				startActivity(intent);
		    }
		});		

		// MI ESTADO
        ImageButton btnMiEstadoInforme = (ImageButton) findViewById(R.id.btnMiEstadoInforme);
        btnMiEstadoInforme.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
		    	
		    	//CrohnContext.setRecordsMinRange(null);
		    	//CrohnContext.setRecordsMaxRange(null);
		    	
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(MiEstado.class.getPackage().getName(), MiEstado.class.getName()));
				startActivity(intent);
		    }
		});		

		// MAS
        ImageButton btnMas = (ImageButton) findViewById(R.id.btnMas);
        btnMas.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(More.class.getPackage().getName(), More.class.getName()));
				startActivity(intent);
		    }
		});		

		// REGISTROS
        ImageButton btnRegistros = (ImageButton) findViewById(R.id.btnRegistros);
        btnRegistros.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
		    	
		        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
				String today = formatter.format(new Date(System.currentTimeMillis()));
				
		    	CrohnContext.setRecordsMinRange(today + " 00:00:00");
		    	CrohnContext.setRecordsMaxRange(today + " 23:59:59");
		    	
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(Registros.class.getPackage().getName(), 
													  Registros.class.getName()));
				startActivity(intent);
		    }
		});		

		// MEDICATION
        ImageButton btnMedication = (ImageButton) findViewById(R.id.btnMedication);
        btnMedication.setOnClickListener (new View.OnClickListener() {
		    public void onClick(View view) {
				Intent intent = new Intent();
				intent.setComponent(new ComponentName(	Medication.class.getPackage().getName(), 
														Medication.class.getName()));
				startActivity(intent);
		    }
		});		

        */
    }

    
    
	protected void onRestart() {
	//	super.onRestart();
	}



	protected void onResume() {
		super.onResume();
        CrohnContext.resetTemporalValues();
	}



	protected void onStart() {
		super.onStart();
        CrohnContext.resetTemporalValues();

        
        /*
        
        try {
			Calendar cal = Calendar.getInstance();
	
			Intent intent        = new Intent(MenuPrincipal.this, CrohnAlarmReceiver.class);
			PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0);
			PendingIntent sende2 = PendingIntent.getBroadcast(this, 123123, intent, 0);
	
			AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
			am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis()+5000, sender); // to be alerted 30 seconds from now
			am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis()+15000, sende2); // to be alerted 15 seconds from now
	
			//To show how alarms are cancelled we will create a new 		Intent and a new PendingIntent with the
		 	//same requestCode as the PendingIntent alarm we want to cancel. In this case, it is 1234567.
	        //Note: The intent and PendingIntent have to be the same as the ones used to create the alarms.

			Intent intent1        = new Intent(MenuPrincipal.this, CrohnAlarmReceiver.class);
			PendingIntent sender1 = PendingIntent.getBroadcast(this, 1234567, intent1, 0);
			AlarmManager am1 = (AlarmManager) getSystemService(ALARM_SERVICE);
			am1.cancel(sender1);

        } catch (Exception e) {
        	Log.e("CROHN", "ERROR IN CODE:"+e.toString());
        }
        
        */
	}
}
